﻿using System.Collections.Generic;
using System.Linq;
using Missbot.AIModule.Base;
using Missbot.Common;
using Missbot.Core.Base;

namespace Missbot.AIModule.Sys
{
    public class VersionMod : IAIModule, IDataMgr
    {
        public override string Name => "版本信息";
        public override string ParentTag => "系统功能";

        public List<VersionInfo> Versions = new();

        public void RefreshData()
        {
            Versions = VersionInfoDA.GetAll().OrderByDescending(v => v.PublishDate).ToList();
        }

        [ModuleEnter(Command = "版本信息", Description = "获取当前的版本信息")]
        public bool ViewVersionInfo(InboxSession session)
        {
            var msg = Versions.First().Format();
            session.SendBack(msg);
            return true;
        }

        [ModuleEnter(Command = "版本信息", Description = "获取指定版本的版本信息", SyntaxHint = "[版本号]")]
        public bool VersionHistoryInfo(InboxSession session, string versionNo)
        {
            var version = Versions.FirstOrDefault(p => p.VersionNum == versionNo);
            if (version == null)
            {
                session.SendBack("未找到指定的版本号！");
                return false;
            }

            session.SendBack(version.Format());
            return true;
        }
    }
}